from django.shortcuts import render
from django.http import HttpResponse
from .models import Post
from django.template.loader import get_template
from datetime import datetime

# Create your views here.

# def index(request):
#     posts = Post.objects.all()
#     post_list = list()
#     for count, post in enumerate(posts):
#         post_list.append("No.{}:" .format(str(count)) + str(post.title) + "<hr>")
#         post_list.append("<small>" + str(post.body) + "</small><br><br>")
#
#     return HttpResponse(post_list)

def index(request):
    template = get_template('index.html')
    posts = Post.objects.all()['title']
    now = datetime.now()
    html = template.render(locals())
    return HttpResponse(html)